package com.config.globalException;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.AfterThrowing;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

/**
 * 全局异常增强，可以捕获非Controller中的异常, 在本系统没有太大用处
 * @since 2022-1-20 23:55:18
 * @version 1.0
 * @author clay
 */
@Aspect
@Slf4j
@Component
public class GlobalExceptionAspect {
    @Pointcut("execution(* com.utils..*.isValid(..))")
    public void pointcut(){
    }

    @AfterThrowing(pointcut = "pointcut()",throwing = "e")
    public void afterThrowing(JoinPoint joinPoint, BusinessException e){
        Object[] args = joinPoint.getArgs();
        System.out.println(args);
        log.error("全局捕获到异常了..............");
        //纪录错误信息
        log.error("系统错误:{}", e.getMessage());
        // todo 想要执行的操作
    }

}
